package org.example.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import lombok.RequiredArgsConstructor;
import org.example.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class AccountController {

    @Autowired
    private AccountService accountService;

    @RequestMapping("/register/{email}/{password}/{code}")
    public int register(@PathVariable String email, @PathVariable String password,@PathVariable String code){
        return accountService.register(email, password, code);
    }

    @RequestMapping("/isRegistered/{email}")
    public Boolean isRegistered(@PathVariable String email){
        return accountService.isRegistered(email);
    }

    @RequestMapping("/login/{email}/{password}")
    public String login(@PathVariable String email, @PathVariable String password){
        return accountService.login(email, password);
    }

    @SentinelResource(value = "infoResource")
    @RequestMapping("/info/{token}")
    public String info(@PathVariable String token){
        return accountService.info(token);
    }

}
